/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.gizelle.myApp.services.crud.impl;

import com.gizelle.myApp.domain.User;
import com.gizelle.myApp.repository.nosql.GenericDAO;
import com.gizelle.myApp.services.crud.UserCrudService;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 *
 * @author Gizelle
 */
@Service("UserCrudService")
@Transactional
public class UserCrudServiceImpl implements UserCrudService {

    @Autowired
    private GenericDAO< User> dao;

    public final void setDao(final GenericDAO< User> daoToSet) {
        this.dao = daoToSet;
        this.dao.setClazz(User.class);
    }

    public UserCrudServiceImpl() {
    }

    @Override
    public User findById(Long id) {
         setDao(dao);
        return dao.findById(id);
    }

    @Override
    public List<User> findAll() {
        setDao(dao);
        return dao.findAll();
    }

    @Override
    public void persist(User entity) {
       setDao(dao);
        dao.persist(entity);
    }

    @Override
    public void merge(User entity) {
         setDao(dao);
        dao.merge(entity);
    }

    @Override
    public void remove(User entity) {
        setDao(dao);
        dao.remove(entity);
    }

    @Override
    public void removeById(Long entityId) {
         setDao(dao);
        User u = dao.findById(entityId);
        dao.remove(u);
    }

    @Override
    public List<User> findInRange(int firstResult, int maxResults) {
         setDao(dao);
        return dao.findInRange(firstResult, maxResults);
    }

    @Override
    public long count() {
         setDao(dao);
        return dao.count();
    }

    @Override
    public User getByPropertyName(String name, String value) {
        setDao(dao);
        return dao.getByPropertyName(name, value);
    }

    @Override
    public List<User> getEntitiesByProperName(String name, String value) {
        setDao(dao);
        return dao.getEntitiesByPropertyName(name, value);
    }
}
